<?php
/**
* @version   $Id: click_process.php 6 2011-08-06 19:59:03Z edo888@gmail.com $
* @package   Heat Map
* @copyright Copyright (C) 2008 - 2011 Edvard Ananyan, Simon Poghosyan. All rights reserved.
* @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
*/

defined('_JEXEC') or die('Restricted access');

$click_x = JRequest::getVar('x', '', 'post', 'int');
$click_y = JRequest::getVar('y', '', 'post', 'int');
$screen_w = JRequest::getVar('screen_w', '', 'post', 'int');

if($click_x != 0 && $click_y != 0 && $screen_w != 0) {
    // Create clicks data table
    $db =& JFactory::getDBO();
    $query_create_table = 'CREATE TABLE IF NOT EXISTS `#__heatmap` (
        `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
        `x` MEDIUMINT UNSIGNED NOT NULL ,
        `y` MEDIUMINT UNSIGNED NOT NULL ,
        `screen` MEDIUMINT UNSIGNED NOT NULL ,
        `date` DATE NOT NULL ,
        `url` TEXT NOT NULL
        ) ENGINE = MYISAM';
    $db->setQuery($query_create_table);
    $db->query();

    $click_url = $_SERVER['HTTP_REFERER'];

    // Insert click data
    $query_insert = "INSERT INTO #__heatmap (`x`, `y`, `screen`, `date`, `url`) VALUES ('$click_x', '$click_y', '$screen_w', NOW(), '$click_url')";
    $db->setQuery($query_insert);
    $db->query();

    exit;
}
?>